package com.ebao.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author snow
 * 
 * @param <V>  VO
 */
public class PageResult<V> {

	private List<V> contents;	// 对象VO集合
	@SuppressWarnings("unused")
	private int startIndex; 	// 起始索引,(currentPage - 1) * pageSize
	private int pageSize; 		// 每页记录
	private int totalCount; 	// 总记录数
	private int currentPage; 	// 当前页
	private int totalPage; 		// 总页数

	public PageResult() {
		contents = new ArrayList<V>(0);
		startIndex = 0;
		pageSize = 20;
		totalCount = 0;
		currentPage = 1;
		totalPage = 0;
	}

	public List<V> getContents() {
		return contents;
	}

	public void setContents(List<V> content) {
		if (content == null)
			contents = new ArrayList<V>(0);
		else
			contents = content;
	}

	public void resetContents(Collection<V> content) {
		List<V> list = new ArrayList<V>();
		list.addAll(content);
		setContents(list);
	}

	public int getStartIndex() {
		return this.startIndex = (this.currentPage - 1) * this.pageSize;
	}
	
	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		if(totalCount % pageSize == 0){
			this.totalPage = totalCount/pageSize;
		}else{
			this.totalPage = totalCount/pageSize + 1; 
		}
	}

	public int getTotalPage() {
		return totalPage;
	}

}
